﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LightSO.CMS.Controllers;
using LightSO.CMS.ServiceUser;

namespace LightSO.CMS
{
    public abstract class BaseController : Controller
    {
        public BaseController()
            : base()
        {
            ViewBag.ContextPath = System.Configuration.ConfigurationManager.AppSettings.Get("ScriptUrl");
        }

        #region 当前登录用户信息
        private LightSO.CMS.ServiceUser.User _currentAccountInfo = null;
        public LightSO.CMS.ServiceUser.User CurrentAccountInfo
        {
            get
            {
                if (_currentAccountInfo == null)
                    _currentAccountInfo = FormsAuth.GetUserData().Parse<LightSO.CMS.ServiceUser.User>();
                return _currentAccountInfo;
            }
        }
        /// <summary>
        /// 用户名称Staffname
        /// </summary>
        public string UserName
        {
            get
            {
                if (CurrentAccountInfo == null)
                    return string.Empty;
                else
                    return CurrentAccountInfo.Name;
            }
        }

        /// <summary>
        /// 用户ID
        /// </summary>
        public long UserId
        {
            get
            {
                if (CurrentAccountInfo == null)
                    return 0;
                else
                    return CurrentAccountInfo.Id;
            }
        }

        /// <summary>
        /// 父ID
        /// </summary>
        public long ParentId
        {
            get
            {
                if (CurrentAccountInfo == null)
                    return 0;
                else
                    return CurrentAccountInfo.ParentId;
            }
        }

        /// <summary>
        /// 登录名
        /// </summary>
        public string LoginName
        {
            get
            {
                if (CurrentAccountInfo == null)
                    return string.Empty;
                else
                    return CurrentAccountInfo.LoginName;
            }
        }

        public bool IsAdministrator
        {
            get
            {
                return CurrentAccountInfo.IsAdmin;
            }
        }
        #endregion

    }
}